﻿#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "data_structure.h"
#include "facility.h"
#include "record.h"
#include "welcome.h"
#include "test.h"

void init_system(System* system) {
    // 初始化链表
    system->facility_link.num = 0;
    system->facility_link.head = NULL;
    system->facility_manager_link.num = 0;
    system->facility_manager_link.head = NULL;
    system->user_link.size = 0;
    system->user_link.head = NULL;
    system->reservation_link.size = 0;
    system->reservation_link.head = NULL;
    //system->user_link.num = 0;
    //system->user_link.head = NULL;
    //system->reservation_link.num = 0;
    //system->reservation_link.head = NULL;
    system->record_link.num = 0;
    system->record_link.head = NULL;
    // 初始化管理员账号密码
    strncpy_s(system->username, MAX_USERNAME, "admin", MAX_USERNAME - 1);
    strncpy_s(system->password, MAX_PASSWORD, "123456", MAX_PASSWORD - 1);
    // 确保字符串以\0结尾
    system->username[MAX_USERNAME - 1] = '\0';
    system->password[MAX_PASSWORD - 1] = '\0';
}

int main() {

    // 初始化系统
    System sys;
    init_system(&sys);
    init_FList(&sys.facility_link);
    read_facility_file(&sys, "..\\src\\facility.txt");
    init_FMList(&sys.facility_manager_link);
    read_facility_manager_file(&sys, "..\\src\\facility_manager.txt");
    init_list(&sys.user_link);
    read_user_data(&sys.user_link);
    init_res_list(&sys.reservation_link);
    read_res_data(&sys.reservation_link);
    init_REList(&sys.record_link);
    read_record_file(&sys, "..\\src\\record.txt");
    //print_records(&sys.record_link);
    set_TList(&sys);     
    //print_facilities(&sys.faclity_link);
    //print_facility_managers(&sys.facility_manager_link);
    //test03();
    //print_records(&sys.record_link);
    //system("pause");
    while (true) {
        system("cls");
        begin();
        char c = judgeA();
        switch (c) {
        case '1':   //登录选择
            system("cls");
            role();
            char character = judgeB();
            chooseB(character, &sys);

            break;
        case '2':   //用户注册
            resigter_st(&sys.user_link);
            save_uers_data(&sys.user_link);
            break;
        case 'q':   //退出系统
            exit(0);
            break;
        }
    }
	return 0;
}